﻿/***************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@gmail.com)

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BaoJianSoft.Web.Extensions.Controls;

namespace BaoJianSoft.Web.Extensions.DynamicPages
{
	/// <summary>
	/// Queryable field class on content entity
	/// </summary>
	public sealed class QueryableField
	{
		private string label;

		/// <summary>
		/// Construct queryable field instance.
		/// </summary>
		/// <param name="fieldName"></param>
		/// <param name="label"></param>
		public QueryableField(string fieldName, string label)
		{
			this.FieldName = fieldName;
			this.Label = label;
			this.FieldType = typeof(string);
		}

		/// <summary>
		/// Get field name.
		/// </summary>
		public string FieldName { get; private set; }

		/// <summary>
		/// Get field displaying label.
		/// </summary>
		public string Label
		{
			set { this.label = value; }
			get { return WebUtility.FormatDisplayText(this.label); }
		}

		/// <summary>
		/// Sets/gets managed type of queryable field. The default value is System.String.
		/// </summary>
		public Type FieldType { get; set; }

		/// <summary>
		/// Sets/gets true when the queryable controls have to be displayed in a new row.
		/// </summary>
		public bool BreakLine { get; set; }

		/// <summary>
		/// Sets/gets queryable field control type. The default value is Text.
		/// </summary>
		public QueryableControlTypes ControlType { get; set; }

		/// <summary>
		/// Sets/gets queryable field default value.
		/// </summary>
		public QueryableFieldDefaultValue DefaultValue { get; set; }

		/// <summary>
		/// Sets/gets selection icon nearby the queryable control.
		/// </summary>
		public QueryFieldSelectionIcon SelectionIcon { get; set; }

		/// <summary>
		/// Get auto-generated control count by QueryableType
		/// </summary>
		public int ControlCount
		{
			get
			{
				switch (this.ControlType)
				{
					case QueryableControlTypes.Text:
					case QueryableControlTypes.RadioButtonList:
						return 1;
					case QueryableControlTypes.Date:
						return 2;
					default:
						return 1;
				}
			}
		}
	}

	/// <summary>
	/// Specifies values of queryable fields.
	/// </summary>
	public sealed class QueryableFieldDefaultValue
	{
		private string defaultOptionText;

		/// <summary>
		/// Sets/gets callback instance to retrieve options.
		/// </summary>
		public IOptionsCallback OptionsCallback { get; set; }

		/// <summary>
		/// Sets/gets initial values for dynamically rendered queryable controls.
		/// </summary>
		public IList<Option> Options { get; set; }

		/// <summary>
		/// Sets/gets default option text - used to search all items.
		/// </summary>
		public string DefaultOptionText
		{
			set { this.defaultOptionText = value; }
			get { return WebUtility.FormatDisplayText(this.defaultOptionText); }
		}

		/// <summary>
		/// Sets/gets default begin date.
		/// </summary>
		public DateTimeControlDefaultValues BeginDate { get; set; }

		/// <summary>
		/// Sets/gets default end date.
		/// </summary>
		public DateTimeControlDefaultValues EndDate { get; set; }
	}

	/// <summary>
	/// Define selection icon nearby queryable control.
	/// </summary>
	public sealed class QueryFieldSelectionIcon
	{
		/// <summary>
		/// True to allow multiple selected.
		/// </summary>
		public bool AllowMultipleSelected { get; set; }

		/// <summary>
		/// Image url of selection icon nearby the queryable control.
		/// </summary>
		public string ImageUrl { get; set; }

		/// <summary>
		/// Url mask of popup page.
		/// </summary>
		public string PopupPageUrlMask { get; set; }

		/// <summary>
		/// Width of popup page.
		/// </summary>
		public string PopupPageWidth { get; set; }

		/// <summary>
		/// Height of popup page.
		/// </summary>
		public string PopupPageHeight { get; set; }
	}
}

